from openpyxl import Workbook

# 示例数据
data = [
    {'Name': 'John', 'Age': 25, 'City': 'New York'},
    {'Name': 'Alice', 'Age': 30, 'City': 'San Francisco'},
    {'Name': 'Bob', 'Age': 22, 'City': 'Chicago'}
]

# 创建一个工作簿
workbook = Workbook()
sheet = workbook.active

# 添加表头，也就是标题
header = list(data[0].keys())
sheet.append(header)

# 添加数据
for row in data:
    sheet.append(list(row.values()))

# 保存工作簿
workbook.save('example.xlsx')
